<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>正则表达式</title>
</head>

<body>
  <h2>敏感字过滤</h2>
  <p>
    <textarea name="" id="area" cols="30" rows="10"></textarea>
  </p>
  <p>
    <button class="sumbit">发布</button>
  </p>
  <p class="res"></p>

  <script>
    //sb nmsl 替换成*
    // 正则
    const reg = /sb|nmsl/g
    const area = document.querySelector("#area")
    const sumbit = document.querySelector(".sumbit")
    const res = document.querySelector(".res")
    
    sumbit.onclick = function(){
      res.innerHTML = area.value.replace(reg,'*');
    }
  </script>
</body>

</html>